package edu.zzuli.model.xt.jqqx.zzjggl;

import java.io.Serializable;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import edu.zzuli.common.MyVisit;
import edu.zzuli.model.orm.po.GG_CZYB;
import edu.zzuli.model.orm.po.GG_JGBH;
import edu.zzuli.model.xt.jqqx.zzjggl.iface.ZzjgglService;

/**
 * @author tianshaojie
 * @date 2011-1-16
 * @discription : 
 */
@SuppressWarnings("serial")
@Controller
public class AddorModJgryAction implements Serializable{
	
	@Resource
	private ZzjgglService zzjgglService;
	
	private GG_CZYB gg_czyb;
	
	private String jgbh;
	
	private String ajaxResult;
	
	public String execute() {
		try {
			gg_czyb.setGG_JGBH(new GG_JGBH(jgbh));
			zzjgglService.saveOrUpdateGG_CZYB(gg_czyb);
			ajaxResult = "success";
		} catch (Exception e) {
			ajaxResult = "error";
		}
		return ajaxResult;
	}
	
	public String addOrModPage() {
		String id = ServletActionContext.getRequest().getParameter("id");
		if (id != null && !"".equals(id)) {
			gg_czyb = (GG_CZYB) zzjgglService.selectSinglePO(new GG_CZYB(id));
			ServletActionContext.getRequest().setAttribute("gg_czyb", gg_czyb);
			ServletActionContext.getRequest().setAttribute("jgbh", gg_czyb.getGG_JGBH().getJgbh());
		} else {
			gg_czyb = new GG_CZYB();
			String jgbh = ServletActionContext.getRequest().getParameter("jgbh");
			if (jgbh != null && jgbh.length() > 0) {
				this.jgbh = jgbh;
			} else {
				MyVisit myVisit = (MyVisit) ServletActionContext. getRequest().getSession().getAttribute("myVisit");
				this.jgbh = myVisit.getGG_JGBH().getJgbh();
			}
			ServletActionContext.getRequest().setAttribute("gg_czyb", gg_czyb);
			ServletActionContext.getRequest().setAttribute("jgbh", this.jgbh);
		}
		return "success";
	}

	public String checkUniqueDlh() {
		if(zzjgglService.checkUniqueDlh(this.gg_czyb.getId(),this.gg_czyb.getDlh())) {
			this.ajaxResult = "success";
		} else {
			this.ajaxResult = "error";
		}
		return this.ajaxResult;
	}
	
	public void setAjaxResult(String ajaxResult) {
		this.ajaxResult = ajaxResult;
	}

	public String getAjaxResult() {
		return ajaxResult;
	}
	
	public GG_CZYB getGg_czyb() {
		return gg_czyb;
	}

	public void setGg_czyb(GG_CZYB ggCzyb) {
		gg_czyb = ggCzyb;
	}

	public void setJgbh(String jgbh) {
		this.jgbh = jgbh;
	}

	public String getJgbh() {
		return jgbh;
	}
}
